Vue.component('dong-table', {
	props:{
		datas:{
			type:Array,
			required:true
		},
		headers:{
			type:Array,
			required:true
		}
	},
	data() {
	    return {
	      tableDatas: []
	    };
	  },
	  watch: {
	    datas: {
	      immediate: true,
	      handler(newDatas) {
	        this.tableDatas = newDatas;
	        // console.log("datas", this.tableDatas);
	      }
	    }
	  },
	methods:{
		timestampToDatetime(timestamp) {
			
		  // 创建一个新的 Date 对象，将时间戳作为参数传递给构造函数
		  var date = new Date(timestamp*1000);
		  // 使用 Date 对象的方法获取年、月、日、小时、分钟和秒
		  var year = date.getFullYear();
		  var month = ("0" + (date.getMonth() + 1)).slice(-2);
		  var day = ("0" + date.getDate()).slice(-2);
		  var hours = ("0" + date.getHours()).slice(-2);
		  var minutes = ("0" + date.getMinutes()).slice(-2);
		  var seconds = ("0" + date.getSeconds()).slice(-2);
		
		  // 拼接成特定的日期时间格式
		  var datetime = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
		
		  return datetime;
		}
		
		
	},
	template :`
	<table id="example5" class="display dataTable no-footer" style="width: 100%; text-align: center;" role="grid">
		<thead>
			<tr role="row">
				
				<th class="sorting" tabindex="0" aria-controls="example5" rowspan="1" colspan="1" aria-label="Patient ID: activate to sort column ascending" v-for="item in headers">{{item.title}}</th>
				<th class="sorting" tabindex="0" aria-controls="example5" rowspan="1" colspan="1" aria-label="Action: activate to sort column ascending">操作</th>
			</tr>
		</thead>
		<tbody id="order_list">
			<tr role="row" class="odd" v-for="item in datas">
				<td v-for="k in headers">
				
				<template v-if="k.key == 'status'">
					<template v-if="item[k.key] == 0">
						待体检
					</template>
					<template v-else-if="item[k.key] == 1">
						体检中
					</template>
					<template v-else-if="item[k.key] == 2">
						已体检
					</template>
				</template>
				<template v-else-if="k.key == 'createTime'">
				
				  {{ timestampToDatetime(item[k.key]) }}
				</template>
				<template v-else>
				        {{item[k.key]}}
				</template>
				</td>
				<td>
					<slot name="operate" :l='item'></slot>
				</td>
			</tr>
	
		</tbody>
	</table>
	`
})